package com.ruoyi.project.cms.api;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.cms.domain.Article;
import com.ruoyi.project.cms.service.ArticleService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@Api("文章API文档")
@RestController
@RequestMapping("/api/article")
public class ArticleApiController extends BaseController {
	@Autowired
	private ArticleService articleService;
	
	@ApiOperation("获取文章列表数据，还可以传入分页数据pageSize（每页显示条数），pageNum（页码），orderByColumn（排序字段），isAsc（desc，asc）")
	@ApiImplicitParam(name = "article", value = "文章信息", required = true, dataType = "Article")
	@PostMapping("/list")
	public TableDataInfo list(Article article) {
		startPage();
		List<Article> ret = articleService.selectArticleList(article);
		return getDataTable(ret);
	}

	@ApiOperation("获取单篇文章数据")
	@ApiImplicitParam(name = "id", value = "文章ID", required = true, dataType = "int")
	@GetMapping("/get/{id}")
	public Article selectByArticleById(@PathVariable Integer id) {
		Article article = articleService.selectArticle(id);
		return article;
	}

}
